home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11607 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: solon.com!not-for-mail
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: const pointer confusion...
  5. Date: 25 Mar 1996 06:21:08 -0600
  6. Organization: none
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4j633k$3dp@solutions.solon.com>
  10. References: <4j06gm$7oa@solutions.solon.com>
  11. Reply-To: fred@genesis.demon.co.uk
  12. NNTP-Posting-Host: solutions.solon.com
  13. X-NNTP-Posting-Host: genesis.demon.co.uk
  14. X-Newsreader: Demon Internet Simple News v1.27
  15. X-Mail2News-Path: genesis.demon.co.uk
  16.  
  17. In article <4j06gm$7oa@solutions.solon.com>
  18.            mangino@planet.net "Reed R. Mangino" writes:
  19.  
  20. >Could someone please straighten me out on this:
  21. >
  22. >1) const int *p = 10;
  23. >        p is a constant pointer to an int, right?
  24.  
  25. No, it is a pointer to const int.
  26.  
  27. >While p can be made to
  28. >        point to something else, *p can never be assigned to, right?
  29.  
  30. That, however, is correct.
  31.  
  32. >2) int *const p;
  33.  
  34. This is a const pointer to int.
  35.  
  36. >        p is a pointer to an integer.  *p can be assigned to, but p can
  37. >        never be made to point to another address in memory, right?
  38.  
  39. Yes.
  40.  
  41. >3) int const *p;
  42. >        What the heck is this?  I can't find anything like this in my 
  43. >        books, but my compiler thinks everything is hunky doory!???
  44.  
  45. It means the same thing as const int *p; Qualifiers (const or volatile)
  46. can appear before or after the type specifier (int in this case) that they
  47. refer to. If they refer to a pointer they must appear after the relevant *.
  48.  
  49. -- 
  50. -----------------------------------------
  51. Lawrence Kirby | fred@genesis.demon.co.uk
  52. Wilts, England | 70734.126@compuserve.com
  53. -----------------------------------------
  54.